package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.IncomeDetail;
import com.whnk.pm.service.IIncomeDetailService;

/**
 * 确认单明细 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-24
 */
@Controller
@RequestMapping("/pm/incomeDetail")
public class IncomeDetailController extends BaseController
{
    private String prefix = "pm/incomeDetail";
	
	@Autowired
	private IIncomeDetailService incomeDetailService;
	
	@RequiresPermissions("pm:incomeDetail:view")
	@GetMapping()
	public String incomeDetail()
	{
	    return prefix + "/incomeDetail";
	}
	
	/**
	 * 查询确认单明细列表
	 */
	@RequiresPermissions("pm:incomeDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IncomeDetail incomeDetail)
	{
		startPage();
        List<IncomeDetail> list = incomeDetailService.selectIncomeDetailList(incomeDetail);
		return getDataTable(list);
	}
	
	/**
	 * 新增确认单明细
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存确认单明细
	 */
	@RequiresPermissions("pm:incomeDetail:add")
	@Log(title = "确认单明细", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IncomeDetail incomeDetail)
	{		
		return toAjax(incomeDetailService.insertIncomeDetail(incomeDetail));
	}

	/**
	 * 修改确认单明细
	 */
	@GetMapping("/edit/{incdId}")
	public String edit(@PathVariable("incdId") Integer incdId, ModelMap mmap)
	{
		IncomeDetail incomeDetail = incomeDetailService.selectIncomeDetailById(incdId);
		mmap.put("incomeDetail", incomeDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存确认单明细
	 */
	@RequiresPermissions("pm:incomeDetail:edit")
	@Log(title = "确认单明细", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IncomeDetail incomeDetail)
	{		
		return toAjax(incomeDetailService.updateIncomeDetail(incomeDetail));
	}
	
	/**
	 * 删除确认单明细
	 */
	@RequiresPermissions("pm:incomeDetail:remove")
	@Log(title = "确认单明细", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(incomeDetailService.deleteIncomeDetailByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param incdId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:incomeDetail:detail")
    @GetMapping("/detail/{incdId}")
    public String detail(@PathVariable("incdId") Integer incdId, ModelMap mmap)
	{
		IncomeDetail incomeDetail = incomeDetailService.selectIncomeDetailById(incdId);
		mmap.put("incomeDetail", incomeDetail);
        return prefix + "/detail";
    }
}
